package com.zzh.fullpermutation;


public class FullPermutation {
    public static void main(String[] args) {
        String str="1234";
        char[] str1 = str.toCharArray();
        System.out.println("需要全排列的数组："+String.valueOf(str1));
        permutation(str1,0,3);
    }
    public static void permutation(char[] str,int from,int to){
        if (from==to){
            System.out.println(String.valueOf(str));
        }
        for (int i=from;i<=to;i++){

            /*
            * 1.交换头位置
            * 2.对下一个到最后进行全排列
            * 3.恢复原状
            * */
            swap(str, from, i);
            permutation(str,from+1,to);
            swap(str,from,i);
        }
    }

    //交换
    public static void swap(char[] str,int from,int to){
        char temp=str[from];
        str[from]=str[to];
        str[to]=temp;
//        return str;
    }

}
